import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: syyyy
 * Date: 2025-08-11
 * Time: 12:52
 */
public class Test {
    public static boolean Valid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (ch == '(' || ch == '{' || ch == '[') {
                stack.push(ch);
            } else {//else说明ch此时是右括号
                if (stack.empty()) {
                    return false;
                }//这个是栈为空，但是字符串不为空的情况
                char ch2 = stack.peek();
                if (ch2 == '(' && ch == ')' || ch2 == '{' && ch == '}' || ch2 == '[' && ch == ']') {//这里ch2才是左括号，ch是右括号
                    stack.pop();
                } else {
                    return false;//这个是不匹配的情况
                }
            }
        }
        if (!stack.empty()) {//这是字符串为空，栈不为空的情况
            return false;
        }
        return true;
    }

    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            String s = tokens[i];
            if (!isOperator(s)) {
                int num = Integer.parseInt(s);
                stack.push(num);
            } else {
                int val2 = stack.pop();
                int val1 = stack.pop();
                int val = 0;
                switch (s) {
                    case "+":
                        val = val1 + val2;
                        break;
                    case "-":
                        val = val1 - val2;
                        break;
                    case "*":
                        val = val1 * val2;
                        break;
                    case "/":
                        val = val1 / val2;
                        break;
                }
                stack.push(val);
            }
        }
        return stack.peek();
    }

    private static boolean isOperator(String s) {//因为运算符只有四种，数字有很多个，所以我判断运算符
        if (s.equals("+") || s.equals("-") || s.equals("*") || s.equals("/")) {
            return true;
        }
        return false;
    }

    public static boolean IsPopOrder(int[] pushV, int[] popV) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushV.length; i++) {
            stack.push(pushV[i]);
            while (j < popV.length && popV[j] == stack.peek()) {
                j++;
                stack.pop();
            }
        }
        if (stack.empty()) {
            return true;
        } else {
            return false;
        }
    }

    public static void main(String[] args) {
//        String s="([]";
//        boolean ret=Valid(s);
//        System.out.println(ret);

//        String[] tokens={"1","2","3","*","+","4","5","*","6","+","7","*","+"};
//        int ret=evalRPN(tokens);
//        System.out.println(ret);
//
//        MyMinStack myMinStack = new MyMinStack();
//        myMinStack.push(-1);
//        myMinStack.push(0);
//        myMinStack.push(2);
//        myMinStack.push(1);
//        myMinStack.push(-2);
//        myMinStack.pop();
//        int min = myMinStack.getMin();
//        System.out.println(min);

        MyQueue queue=new MyQueue();
        queue.offer(12);
        queue.offer(23);
        queue.offer(34);
        queue.offer(45);
        queue.offer(56);
        System.out.println(queue.poll());
    }
}